﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Media;
using System.ComponentModel;
using System.Diagnostics;
namespace Negocio
{
    public class ReferenceMeasure : PersistentObject,INotifyPropertyChanged, ICloneable, IEditableObject
    {
        private string name;
        private float value;
        private ReferenceMeasure copy;

        public ReferenceMeasure()
        {
            this.Name = "";
            this.Value = 0;
        }
        
        public string Name 
        {
            get { return this.name;}
            set { this.name = value;}
        }

        public float Value 
        {
            get { return this.value;}
            set { this.value = value;}
        }


        public override bool Equals(object obj)
        {
            bool ret = false;
            try { 
              
              if (obj != null)
            {
                ret = this.Name.Equals(((ReferenceMeasure)obj).Name);
            }
            
            }
            catch(InvalidCastException)
            {
            }
            return ret;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion INotifyPropertyChanged

        #region ICloneable

        public object Clone()
        {
            ReferenceMeasure reference = (ReferenceMeasure)this.MemberwiseClone();

            // need to manually copy Uri
           // person.Homepage = new Uri(this.Homepage.OriginalString);

            return reference;
        }
        public void CopyFrom(ReferenceMeasure reference)
        {
            this.name = reference.Name;
            this.value = reference.Value;
            
        }
        #endregion ICloneable

        #region IEditableObject Members

        public void BeginEdit()
        {
            if (this.copy == null)
            {
                this.copy = new ReferenceMeasure();
            }

            this.copy = (ReferenceMeasure)Clone();
        }

        public void CancelEdit()
        {
            this.CopyFrom(this.copy);
        }

        public void EndEdit()
        {
            this.copy = null;
        }

        #endregion
    }
}
